import { useSearchParams } from '@@/exports';
import { Button } from 'antd';
import { useEffect, useState } from 'react';
import styles from './meetingShareRecordRemind.less';

const MeetingShareRecordRemind = () => {
  const [searchParams] = useSearchParams();
  console.log('searchParams', searchParams.getAll('meetingRemindData'));
  const [meetingRemindData] = searchParams.getAll('meetingRemindData');

  const [remindData, setRemindData] = useState<{
    messageType: string;
    userId: string;
    userName: string;
    pushFlag: boolean;
    pullFlag: boolean;
    isRecordFlag: boolean;
  }>();

  useEffect(() => {
    console.log(
      '-----------------meetingRemindData:',
      JSON.parse(meetingRemindData),
    );
    const meetingRemindInfo = JSON.parse(meetingRemindData);
    console.log('meetingRemindInfo', meetingRemindInfo);
    setRemindData(meetingRemindInfo);
  }, []);

  return (
    <>
      <div className={styles.bodyDiv}>
        {remindData?.pullFlag && remindData.isRecordFlag && (
          <div className={styles.contentDiv}>
            <div className={styles.meetingMessage}>
              <span className={styles.meetingSpan}>此会议正在录制中</span>
            </div>
            <div className={styles.meetingInfo}>
              <div className={styles.rowDiv}>
                主持人 发起了录制，会议结束后可联系TA获取录制文件
                ，如果留在会议中，则表示你同意录制
              </div>
            </div>
            <div className={styles.buttonDiv}>
              <Button
                className={styles.meetingButton}
                onClick={() => {
                  window.tm!.ipcRenderer.send('record-notice-to-leave-meeting');
                }}
              >
                离开会议
              </Button>
              <Button
                className={styles.meetingButton}
                onClick={() => {
                  window.tm?.ipcRenderer.send('closeMeetingShareRecordRemind');
                }}
              >
                我知道了
              </Button>
            </div>
          </div>
        )}

        {remindData?.pushFlag && remindData.isRecordFlag && (
          <div className={styles.contentDiv}>
            <div className={styles.meetingRecordMessage}>
              <span className={styles.meetingSpan}>
                {remindData.userName} 请求你开启云录制
              </span>
            </div>
            <div className={styles.buttonRecordDiv}>
              <Button
                className={styles.meetingButton}
                onClick={() => {
                  window.tm?.ipcRenderer.send('closeMeetingShareRecordRemind');
                }}
              >
                暂不录制
              </Button>
              <Button
                className={styles.meetingButton}
                onClick={() => {
                  window.tm?.ipcRenderer.send('set-recordClick-events', true);
                  setTimeout(() => {
                    window.tm?.ipcRenderer.send(
                      'closeMeetingShareRecordRemind',
                    );
                  }, 100);
                }}
              >
                开启录制
              </Button>
            </div>
          </div>
        )}
      </div>
    </>
  );
};

export default MeetingShareRecordRemind;
